﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Threading;
using System.Windows.Forms;

namespace demo05_坐标变换
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen p = new Pen(Color.Blue, 2);
            for (int i = 0; i < 20; i++)
            {
                g.TranslateTransform(5, 5);
                g.DrawRectangle(p, 60, 80, 100, 150);
                Thread.Sleep(10);
            }
            p = new Pen(Color.Red, 2);
            for (int i = 0; i < 20; i++)
            {
                g.TranslateTransform(10, -5);
                g.DrawRectangle(p, 60, 80, 100, 150);
                Thread.Sleep(10);
            }
            g.Dispose();
            p.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.TranslateTransform(280, 200); //改变原点
            Pen p = new Pen(Color.Blue, 2);
            for (int i = 0; i < 24; i++)
            {
                g.RotateTransform(15);

                g.DrawRectangle(p, 0, 0, 100, 150);
                Thread.Sleep(10);
            }
            Thread.Sleep(2000);
            Point p1 = new Point(0, 0);
            Point p2 = new Point(100, 150);
            Brush brush = new LinearGradientBrush(p1, p2, Color.Red, Color.Yellow);
            for (int i = 0; i < 18; i++)
            {
                g.RotateTransform(20);
                g.FillEllipse(brush, 0, 0, 100, 150);
                Thread.Sleep(10);
            }
            g.Dispose();
            p.Dispose();
            brush.Dispose();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.TranslateTransform(280, 200); //改变原点
            Pen p = new Pen(Color.Blue, 2);
            for (int i = 0; i < 48; i++)
            {
                g.DrawRectangle(p, 0, 0, 100, 150);
                g.RotateTransform(10);
                g.ScaleTransform(0.95f, 0.95f);

                Thread.Sleep(10);
            }
            g.Clear(BackColor);
            p = new Pen(Color.Red, 2);  //改颜色
            g.RotateTransform(180);     //改变输出方向
            for (int i = 0; i < 48; i++)
            {
                g.DrawRectangle(p, 0, 0, 100, 150);
                g.RotateTransform(-10);
                g.ScaleTransform(1.055f, 1.055f);

                Thread.Sleep(10);
            }
            g.Dispose();
            p.Dispose();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.Clear(BackColor);
            g.Dispose();
        }
    }
}
